package org.objective.dal.commands;

import org.common.service.ServiceRegister;
import org.objective.command.AuthToken;
import org.objective.command.Command;
import org.objective.command.CommandResult;
import org.objective.dal.ColumnMapper;
import org.objective.service.DalService;

import static org.utils.fp.collection.CollectionFactory.*;

/**
 *
 * @author gus
 */
public class GetAllObjectsCommand implements Command
{
    private static final long serialVersionUID = -6370103626069409627L;

    private final ColumnMapper rowMapper;
    private final Class type;

    public GetAllObjectsCommand(ColumnMapper rowMapper, Class type)
    {
        this.rowMapper = rowMapper;
        this.type = type;
    }

    @Override
    public Object[] getParameters()
    {
        return array(rowMapper);
    }

    @Override
    public CommandResult execute(ServiceRegister provider, AuthToken token) throws Exception
    {
        DalService service =  provider.getService(DalService.class);
        return  service.getAllObjects(rowMapper);
    }
}
